#ifndef ARRAY_OPS_H
#define ARRAY_OPS_H

#include "Common.h"

template<typename T>
class Array {
private:
    T* data;
    int size;
    int capacity;

public:
    Array(int initCapacity = 10) : size(0), capacity(initCapacity) {
        data = new T[capacity];
    }
    
    ~Array() {
        delete[] data;
    }
    
    Array(const Array& other) : size(other.size), capacity(other.capacity) {
        data = new T[capacity];
        for (int i = 0; i < size; i++) {
            data[i] = other.data[i];
        }
    }
    
    Array& operator=(const Array& other) {
        if (this != &other) {
            delete[] data;
            size = other.size;
            capacity = other.capacity;
            data = new T[capacity];
            for (int i = 0; i < size; i++) {
                data[i] = other.data[i];
            }
        }
        return *this;
    }
    
    T value(int index) const {
        if (index < 0 || index >= size) {
            throw out_of_range("Index out of range");
        }
        return data[index];
    }
    
    void assign(int index, const T& val) {
        if (index < 0 || index >= capacity) {
            throw out_of_range("Index out of range");
        }
        if (index >= size) {
            size = index + 1;
        }
        data[index] = val;
    }
    
    int getSize() const {
        return size;
    }
    
    int getCapacity() const {
        return capacity;
    }
    
    void print() const {
        cout << "[";
        for (int i = 0; i < size; i++) {
            cout << data[i];
            if (i < size - 1) cout << ", ";
        }
        cout << "]" << endl;
    }
    
    static void testArray();
    
    static void interactiveTest();
};

#endif